import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        // 存储token
        token: sessionStorage.getItem('Authorization') ? sessionStorage.getItem('Authorization') : ''
    },
    mutations: {
        // 设置token，并将token存入localStorage
        setToken(state, user) {
            console.log('store js ');
            state.token = user.token
            sessionStorage.setItem('Authorization', user.token)
        },
        //清除token，并将token存入localStorage
        delToken(state) {
            state.token = ''
            sessionStorage.removeItem('Authorization')
        }
    },
    actions: {},
    modules: {}
})
